import store from '@/store/index.js'
import {
	setToken,
	getToken
} from '@/utils/token.js'
//缓存用户信息
export const setUserInfo = (data) => {
	uni.setStorageSync('userInfo', data);
}
//获取缓存的用户信息
export const getUserInfo = () => {
	return uni.getStorageSync('userInfo');
}
//获取缓存的用户信息
export const setLogin = (data) => {
	store.dispatch('showAuthModal', '');
	store.commit('setIsLogin', true)
	uni.setStorageSync('login', data.data);
	uni.setStorageSync('version', 1);
	uni.setStorageSync('phone', data.data && data.data.usrTel);
	uni.setStorageSync('useNum', String(data.data.craftsmanId));
	if (data.token) {
		uni.setStorageSync('token', uni.getStorageSync('phone') + '_' + data.token);
	}
	uni.setStorageSync('userInfo', data.data);
	// #ifdef H5
	uni.setStorageSync('jumpUrlCard', window.location.href);
	// #endif
	uni.navigateTo({
		url: `/pages/meSub/selectID?useNum=${getToken('useNum')}`
	})
}
//获取用户token
export const getUserToken = () => {
	return uni.getStorageSync('token');
}

//缓存Appid
export const setUserOpenid = (data) => {
	if (uni.getStorageSync('assoId')) {
		uni.setStorageSync('Openid', data);
	} else {
		uni.setStorageSync('mpOpenid', data);
	}
}
//获取缓存的Appid
export const getUserOpenid = () => {
	if (uni.getStorageSync('assoId')) {
		return uni.getStorageSync('Openid');
	} else {
		return uni.getStorageSync('mpOpenid');
	}
}